package logic

import (
	"bw-renting/house-rpc/house"
	"context"

	"bw-renting/api/internal/svc"
	"bw-renting/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetHouseListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetHouseListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetHouseListLogic {
	return &GetHouseListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// TODO: 获取房源列表
func (l *GetHouseListLogic) GetHouseList(req *types.GetHouseListReq) (resp *types.Data, err error) {
	// todo: add your logic here and delete this line
	res, _ := l.svcCtx.HouseServer.GetHouse(context.Background(), &house.GetHouseReq{
		Title:     req.Title,
		Acreage:   int64(req.Acreage),
		RoomCount: int64(req.RoomCount),
	})
	if res.Status == "0" {
		return &types.Data{
			Code:    10001,
			Message: "获取房源列表失败",
			Data:    nil,
		}, err
	}
	return &types.Data{
		Code:    200,
		Message: "获取房源列表成功",
		Data: map[string]string{
			"list": res.Status,
		},
	}, err
}
